package com.hongxun.modules.bss.service.impl;

import java.math.BigDecimal;
import java.util.UUID;

import com.hongxun.modules.bss.dao.DMaterialModelItemDao;
import com.hongxun.modules.bss.entity.DMaterialModelItemEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

import com.hongxun.modules.bss.dao.DMaterialModelDao;
import com.hongxun.modules.bss.entity.DMaterialModelEntity;
import com.hongxun.modules.bss.service.DMaterialModelService;


@Service("dMaterialModelService")
public class DMaterialModelServiceImpl implements DMaterialModelService {
    @Autowired
    private DMaterialModelDao dMaterialModelDao;

    @Override
    public DMaterialModelEntity queryObject(String guid) {
        return dMaterialModelDao.queryObject(guid);
    }

    @Override
    public List<DMaterialModelEntity> queryList(Map<String, Object> map) {
        return dMaterialModelDao.queryList(map);
    }

    @Override
    public int queryTotal(Map<String, Object> map) {
        return dMaterialModelDao.queryTotal(map);
    }

    @Override
    public void save(DMaterialModelEntity dMaterialModel) {
        if (dMaterialModel.getGuid() == null || dMaterialModel.getGuid().equals("")) {
            dMaterialModel.setGuid(UUID.randomUUID().toString());
        }

        dMaterialModelDao.save(dMaterialModel);
    }

    @Override
    public void update(DMaterialModelEntity dMaterialModel) {
        dMaterialModelDao.update(dMaterialModel);
    }

    @Override
    public void delete(String guid) {
        dMaterialModelDao.delete(guid);
    }

    @Override
    public void deleteBatch(String[] guids) {
        dMaterialModelDao.deleteBatch(guids);
    }

    @Override
    public void insertOrReplaceOrDelete(List<DMaterialModelEntity> entities) {
        for (DMaterialModelEntity d : entities) {
            if (d.getDatastate().equals("删除")) {
                dMaterialModelDao.delete(d.getGuid());
            } else {
                DMaterialModelEntity dMaterialCostEntity = dMaterialModelDao.queryObject(d.getGuid());
                if (dMaterialCostEntity == null) {
                    dMaterialModelDao.save(d);
                } else {
                    dMaterialModelDao.update(d);
                }
            }
        }
    }

}
